package cn.com.cetccst.uicomponents.binding.swipeRefresh;

import android.util.TypedValue;

import androidx.databinding.BindingAdapter;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;

import cn.com.cetccst.uicomponents.R;

public class SwipeRefresh {

    @BindingAdapter(value = {"swipeRefreshListener", "refreshing"}, requireAll = false)
    public static void initSwipe(SwipeRefreshLayout swiperefreshlayout, SwipeRefreshLayout.OnRefreshListener refreshListener, boolean refreshing) {
        if(refreshListener!=null) {
            swiperefreshlayout.setProgressBackgroundColorSchemeResource(android.R.color.white);
            swiperefreshlayout.setColorSchemeResources(R.color.uicomponents_theme_color);
            swiperefreshlayout.setProgressViewOffset(true, 0, (int) TypedValue
                    .applyDimension(TypedValue.COMPLEX_UNIT_DIP, 24, swiperefreshlayout.getContext().getResources()
                            .getDisplayMetrics()));
            swiperefreshlayout.setOnRefreshListener(refreshListener);
        }
        swiperefreshlayout.setRefreshing(refreshing);
    }
}
